DECLARE @xml XML

SET @xml = 
(
    SELECT
        FragmentId           = ISNULL(FragmentId,0)
    ,   FragmentName         = ISNULL(FragmentName,'')
    ,   FragmentDisplayName  = CAST(ISNULL(FragmentDisplayName,'') AS xml)
    ,   SortOrdinal          = ISNULL(CAST(SortOrdinal AS varchar(16)),'')
    ,   ItemChar             = CAST(ISNULL(ItemChar,'') AS xml)
    ,   ItemText             = CAST(ISNULL(CAST(ItemText AS varchar(MAX)),'') AS xml)
    ,   CreateDate           = ISNULL(Core.dbo.fDateFormat(@GlobalDateFormat,CreateDate),'')
    ,   EndDate              = ISNULL(Core.dbo.fDateFormat(@GlobalDateFormat,EndDate),'')
    ,   ModificationDate     = ISNULL(Core.dbo.fDateFormat(@GlobalDateFormat,ModificationDate),'')
    ,   DocumentId           = ISNULL(CAST(DocumentId AS varchar(16)),'')
    ,   PrevFragmentId       = ISNULL(CAST(PrevFragmentId AS varchar(16)),'')
    ,   NextFragmentId       = ISNULL(CAST(NextFragmentId AS varchar(16)),'')
    ,   IsPrevious           = ISNULL(IsPrevious,0)
    ,   IsNext               = ISNULL(IsNext,0)
    ,   IsWrapper            = ISNULL(IsWrapper,0)
    ,   ClientId             = ISNULL(ClientId,'')
    ,   IsActive             = ISNULL(IsActive,0)
    ,   FragmentBranch       = CAST(dbo.fGetWebXmlString('FragmentBranch',FragmentId) AS xml)
    FROM
        Fragment
    WHERE
        FragmentId = @FragmentId
    FOR XML AUTO, ELEMENTS
)

SELECT @xml
